package com.practise.demo.controller;

import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @PostMapping("/login")
    public Boolean login(String name, String password, HttpSession session){
        //步骤
        // 1.判断是否为空
        // 2.不为空时，对比是否与账号密码
        // 3.存储session
        // 4，返回结果
        if(!StringUtils.hasLength(name) || !StringUtils.hasLength(password)){
            return false;
        }
        String n = "admin";
        String p = "123456";
        if(n.equals(name) && p.equals(password)){
            session.setAttribute("name",name);
            return true;
        }
        return false;
    }
}
